package com.zxy.h2demo;

import org.h2.tools.Server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * App3.
 * 
 * Created by zxybird on 17/1/13.
 */
public class App3 {

  private static String port = "8082";

  public static void main(String[] args) {
    try {
      Server server = null;
      server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", port).start();
      Connection connection = null;
//      connection = DriverManager.getConnection("jdbc:h2:tcp://localhost:" + port + "/mem:trump;MODE=MySQL;DB_CLOSE_DELAY=-1;");
      connection = DriverManager.getConnection("jdbc:h2:mem:");
      Statement stmt = connection.createStatement();
      stmt.execute("CREATE SCHEMA IF NOT EXISTS TRUMP;");
      stmt.execute("SET SCHEMA TRUMP;");

      stmt.execute("CREATE TABLE `TRUMP`.`TEST_MEM` (ID INT PRIMARY KEY,NAME VARCHAR(255));");
      stmt.execute("INSERT INTO `TRUMP`.`TEST_MEM` VALUES (1, 'Hello_Mem');");

      System.out.println("链接创建成功！");

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
